package com.vmix.vmixmobiledemo;  


import java.util.HashMap;
import java.lang.ref.SoftReference;

import android.graphics.Bitmap;

public class SoftCache
{
    private HashMap<String, SoftReference<Bitmap>>  map = new HashMap<String, SoftReference<Bitmap>>();

    public Bitmap get(String key)
    {
        SoftReference<Bitmap> softRef = map.get(key);

        if (softRef==null)
            return null;

        return softRef.get();
    }

    public Object put(String key, Bitmap value)
    {
    	SoftReference<Bitmap> softRef = map.put(key, new SoftReference<Bitmap>(value));

        if (softRef==null)
            return null;

        Object oldValue = softRef.get();
        softRef.clear();

        return oldValue;
    }

    public Object remove(String key)
    {
        SoftReference<Bitmap> softRef = map.remove(key);

        if (softRef==null)
            return null;

        Object oldValue = softRef.get();
        softRef.clear();

        return oldValue;
    }
}
